home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Network / Remote / Remote Launch < prev    next >
Encoding:
Text File  |  1999-03-04  |  4.8 KB  |  194 lines  |  [TEXT/ToyS]

  1. -- User setable properties
  2. property kasAllowAlerts : true -- Set to false to stop any alerts from appearing
  3. property kasServerAlerts : true -- Set to false to stop warnings about missed servers
  4. property kasFinder : "Finder" -- name of application to open RemoteLaunchers
  5. property kasAppendage : " ->" -- Appended to file name if we can't use original
  6.  
  7. -- Internal/User setable globals
  8. property kasLinkNeed : false
  9. property kasLinkUserDft : "CasaVision" -- Our friend on all machines
  10. property kasLinkPassDft : "" -- Our friend's password on all machines
  11.  
  12. global gasLinkSet -- Has the friend been looked up?
  13. global gasLinkUser -- Used to connect (KeyChain Lookup)
  14. global gasLinkPass
  15.  
  16. -- Internal globals
  17. global gasOurZone -- Set to zone of gasOurAlias
  18. global gasOurServer -- Set to server of gasOurAlias
  19. global gasOurVol -- Name of volume alias resides on
  20. global gasOurAlias -- The alias we own
  21. global gasOurName -- Name of original alias
  22.  
  23.  
  24. on open fsObjs
  25.     set gasLinkSet to false
  26.     
  27.     repeat with fsObj in fsObjs
  28.         OpenOne(fsObj)
  29.     end repeat
  30. end open
  31.  
  32.  
  33. on OpenOne(fsObj)
  34.     set aInfo to alias info from fsObj
  35.     
  36.     set gasOurZone to alias zone of aInfo
  37.     set gasOurServer to alias server of aInfo
  38.     set gasOurVol to alias volume of aInfo
  39.     GetFriend(false)
  40.     
  41.     RemoteOpen(fsObj)
  42. end OpenOne
  43.  
  44.  
  45. on RemoteOpen(fileAlias)
  46.     talk as user gasLinkUser ¬
  47.         with password gasLinkPass ¬
  48.         on server gasOurServer ¬
  49.         in AppleTalk zone gasOurZone
  50.     
  51.     try
  52.         -- Don't wait for a response, assume the aliases are correct
  53.         tell application kasFinder of machine gasOurServer ¬
  54.             of zone gasOurZone to open fileAlias
  55.     on error err
  56.         if (kasServerAlerts) then
  57.             ShowConnectAlert(kasFinder, err)
  58.         else
  59.             beep
  60.         end if
  61.     end try
  62. end RemoteOpen
  63.  
  64.  
  65. on GetFriend(override) -- Should later use some modifier key to override?!?
  66.     GetOneFriend(override)
  67. end GetFriend
  68.  
  69.  
  70. on GetOneFriend(override)
  71.     set isLink to true -- Only linking in this script!
  72.     set userMode to "linking"
  73.     set passButtons to {"Cancel", "OK"}
  74.     set passButton to 2
  75.     
  76.     if (gasLinkSet) then
  77.         set defUser to gasLinkUser
  78.         set defPass to gasLinkPass
  79.     else
  80.         set defUser to kasLinkUserDft
  81.         set defPass to kasLinkPassDft
  82.     end if
  83.     
  84.     set usrPwd to KeyChainLookUp(gasOurZone, gasOurServer, isLink)
  85.     
  86.     if (override or usrPwd is {}) then
  87.         set chosen to display dialog ¬
  88.             "Enter the friendly " & userMode & ¬
  89.             " user's name…" default answer defUser ¬
  90.             default button 2 with icon note
  91.         
  92.         if (the button returned of chosen is "OK") then
  93.             set defUser to the text returned of chosen
  94.         else
  95.             return
  96.         end if
  97.         
  98.         set chosen to display dialog ¬
  99.             "Enter the friendly " & userMode & ¬
  100.             " user's password…" buttons passButtons ¬
  101.             default answer defPass default button passButton with icon note
  102.         
  103.         if (the button returned of chosen is not "Cancel") then
  104.             set defPass to the text returned of chosen
  105.         else
  106.             return
  107.         end if
  108.         
  109.         -- Save encrypted user/pass for future access
  110.         KeyChainSave(gasOurZone, gasOurServer, isLink, defUser, defPass, "")
  111.     else
  112.         set defUser to item 1 of usrPwd
  113.         set defPass to item 2 of usrPwd
  114.     end if
  115.     
  116.     set gasLinkSet to true
  117.     set gasLinkUser to defUser
  118.     set gasLinkPass to defPass
  119. end GetOneFriend
  120.  
  121.  
  122. on PutAwayVol(volName)
  123.     -- Volume
  124.     try
  125.         tell application "Finder" to put away item named volName
  126.     on error
  127.         beep
  128.     end try
  129. end PutAwayVol
  130.  
  131.  
  132. on IsVolMounted(volName)
  133.     -- Volume
  134.     try
  135.         set x to (volName & ":") as alias
  136.         return true
  137.     on error
  138.         return false
  139.     end try
  140. end IsVolMounted
  141.  
  142.  
  143. on ShowMountAlert()
  144.     ShowServerAlert("Couldn't mount volume " & gasOurVol & ¬
  145.         " from " & gasOurServer ¬
  146.         & " in zone " & gasOurZone)
  147. end ShowMountAlert
  148.  
  149.  
  150. on ShowConnectAlert(appName, msg)
  151.     ShowServerAlert("Couldn't connect to " & appName & " on " & ¬
  152.         gasOurServer & " in zone " & gasOurZone & return & return & ¬
  153.         "(" & msg & ")")
  154. end ShowConnectAlert
  155.  
  156.  
  157. on ShowServerAlert(msg)
  158.     set choice to ¬
  159.         display dialog msg buttons {"Reenter Password", "OK"} ¬
  160.             default button 2 with icon stop
  161.     
  162.     if (button returned of choice is not "OK") then GetFriend(true)
  163. end ShowServerAlert
  164.  
  165.  
  166. property kasKeyChainPassword : "PowerScript" -- Encrypt stored data with this
  167. property kasPrefsFileName : "PowerScript Prefs" -- File name in <Preferences>
  168.  
  169. on KeyChainLookUp(zoneName, serverName, isLinking)
  170.     set prefOwner to "πSRV"
  171.     if (isLinking) then set prefOwner to "πLNK"
  172.     
  173.     try
  174.         set myKeyData to load preference named (zoneName & ":" & serverName) ¬
  175.             of type prefOwner in file named kasPrefsFileName
  176.     on error
  177.         return {}
  178.     end try
  179.     
  180.     return (encrypt the data myKeyData with password kasKeyChainPassword)
  181. end KeyChainLookUp
  182.  
  183.  
  184. on KeyChainSave(zoneName, serverName, isLinking, usr, pwd, ntPwd)
  185.     set myKey to encrypt the data {usr, pwd, ntPwd} with password kasKeyChainPassword
  186.     
  187.     set prefOwner to "πSRV"
  188.     if (isLinking) then set prefOwner to "πLNK"
  189.     
  190.     save preference myKey named (zoneName & ":" & serverName) ¬
  191.         of type prefOwner ¬
  192.         in file named kasPrefsFileName
  193. end KeyChainSave
  194.